angular.module('searchCtrl.controllers', [])
.controller('searchCtrl', function($scope) {
	$scope.w_back = function(){
		window.history.back()
	};
	 var search_data = localStorage.getItem('conPre');  
            if(search_data!=""){
            	search_data= JSON.parse(search_data);
            	if((typeof search_data) == Object){
            		search_data= [];
            	}
            }else{
            	search_data= [];
            }
	$scope.wconList = search_data;
	$scope.deleteReco = [];
	$scope.confirmPress = function(e){
		var key = e.which;
	    if (key == 13) {
            e.preventDefault();
            var str1 = e.target.value;
            var search_data = localStorage.getItem('conPre');  
            if(search_data!=""){
            	search_data = JSON.parse(search_data);
            }else{
            	search_data = [];
            }
        // console.log(search_data)
            if(search_data.indexOf(str1) == -1 && str1!= ''){
            	search_data.unshift(str1)
            }
            $scope.wconList = search_data;
            if($scope.deleteReco.indexOf(str1)==-1 && str1!= ''){           	
                $scope.deleteReco.unshift(str1);
                var delStr = JSON.stringify($scope.deleteReco)
                localStorage.setItem('conPre',delStr);
            }
			// console.log('跳转了')
			var hre = './#/tab/home/list/search/'+ str1;
      		location.href = hre;
        }
	};
	$scope.searchRecord = function(i){
		var search_data = localStorage.getItem('conPre');  
            if(search_data!=""){
            	search_data = JSON.parse(search_data);
            }else{
            	search_data = [];
            }
        var w_content = $('.list').eq(i).html()
        search_data.splice(search_data.indexOf(w_content)-1,1)
        search_data = JSON.stringify(search_data)
        localStorage.setItem('conPre',search_data);
		$('.list').eq(i).css('display','none');
		$scope.wconList.splice(i,1);
//		$scope.deleteReco.splice(i,1)
	}
	
	
	$scope.clearRec = function(){
		$scope.wconList = [];
		$scope.deleteReco = [];
		$('.list').css('display','none')
		localStorage.setItem('conPre',"");
	}

})

